package com.wh.minio.container.listener;

import com.wh.minio.container.common.Constants;
import com.wh.minio.container.common.PropertiesUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/***
 * 初始化上下文系统信息
 * @Package com.wh.technology.xbox.entity.client
 * @author 谢泽鹏
 * @date 2016年11月07日 下午15:10
 * @Copyright 个人版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2016
 * @version V1.0
 */
public class ContextStartupListener implements ServletContextListener {

        private static final Log logger = LogFactory.getLog(ContextStartupListener.class);


        @Override
        public void contextDestroyed(ServletContextEvent arg0) {

        }

        @Override
        public void contextInitialized(ServletContextEvent event) {
            try {
                logger.info("上下文初始化->>contextInitialized->>开始");
                //加载属性文件
                ClassLoader classLoader = ContextStartupListener.class.getClassLoader();
                //初始化[实名认证]配置
                PropertiesUtils.setFileName("minio.properties");
                PropertiesUtils.initProperties(classLoader);
                Constants.endpoint  = PropertiesUtils.getPropertiesByKey("wh.minio.endpoint");
                Constants.port = Integer.parseInt(PropertiesUtils.getPropertiesByKey("wh.minio.port"));
                Constants.secretKey = PropertiesUtils.getPropertiesByKey("wh.minio.secretKey");
                Constants.accessKey = PropertiesUtils.getPropertiesByKey("wh.minio.accessKey");
            } catch (Exception e) {
                e.printStackTrace();
                logger.error("上下文初始化->>contextInitialized->>初始化异常Exception " + e.getMessage());
            }
                logger.info("上下文初始化->>contextInitialized->>结束");
        }

}
